package com.finstone.data.spider.eshop.service.impl;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Spider;

import com.finstone.data.spider.eshop.pipeline.EShopGoodsDetailParamPipline;
import com.finstone.data.spider.eshop.processor.EShopGoodsDetailParamProcessor;
import com.finstone.data.spider.eshop.service.AbstractSpiderService;

@Component
public class EShopGoodsDetailParamService extends AbstractSpiderService<String> {

	@Autowired
	private EShopGoodsDetailParamProcessor eShopGoodsParamProcessor;

	@Autowired
	private EShopGoodsDetailParamPipline eShopGoodsParamPipline;

	@Override
	@PostConstruct
	public void init() {
		spider = Spider.create(eShopGoodsParamProcessor).addPipeline(eShopGoodsParamPipline).thread(5);
	}

	@Override
	protected void doPutTask(String goodsid) {
		String url = "http://www.lenovo.com.cn/product/" + goodsid+".html";
		Request request = new Request(url);
		request.putExtra("goods_id", goodsid);
		spider.addRequest(request);
	}
}
